package com.eyaomall.wxmall.common.helper;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Copyright 2015-2020 www.eyaomall.cn
 * All rights reserved.
 *
 * @author archer
 * @version 1.0
 * @project mall
 * @date 16/4/6
 *
 * 生成15位订单号
 * 时间戳13位 + seed(截取末2位)
 */

public class CodeHelper {

    public static String getCode(Integer seed){
        String timeStamp = Long.toString(System.currentTimeMillis());
        String seeds = "00" + seed.toString();
        seeds = seeds.substring(seeds.length()-2, seeds.length());
        return timeStamp + seeds;
    }

    public static String getSerialNumber(Integer seed){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateStamp = sdf.format(new Date());
        String seeds = "";
        if(seed.toString().length()>=6){
            seeds = seed.toString();
        }else{
            seeds = "000000" + seed.toString();
            seeds = seeds.substring(seeds.length()-6, seeds.length());
        }
        return dateStamp + seeds;
    }
    
    /**
     * 生产随机数
     * @return
     */
	public static String getRandomCode(int num){
    	String ret = "";
    	int a[] = new int[num];
        for(int i=0;i<a.length;i++) {

            a[i] = (int)(10*(Math.random()));

            ret+=a[i];
        }
        return String.valueOf(new Date().getTime()) + ret;
    }
}
